package top.lyjwn.todo.weinxin.data.bjnews;

import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 *
 * @author luoyujie
 *
 */
public class BjnewsUserAccessToken  {

	private static final Logger log = LoggerFactory.getLogger("error");

	private String accessToken;
	private long expiresIn;
	/**
	 * accessToken过期时间
	 */
	private long expiresInTime;
	private String refreshToken;
	/**
	 * refreshToken 过期时间
	 */
	private long expiresTime;
	private String openid;
	private String scope;

	/**
	 * 错误
	 */
	/**
	 * 错误返回码
	 */
	private String errcode;

	/**
	 * 说明
	 */
	private String errmsg;

	public BjnewsUserAccessToken() {
	}

	public static BjnewsUserAccessToken builder(JSONObject jsonObject) {
		try {
			return jsonObject.toJavaObject(BjnewsUserAccessToken.class);
		} catch (JSONException e) {
			log.error("BjnewsUserAccessToken 转换失败", e);
		}
		return null;
	}

	public BjnewsUserAccessToken(String accessToken, long expiresIn, String refreshToken, String openid, String scope) {
		this.accessToken = accessToken;
		this.expiresIn = expiresIn;
		Date date = new Date();
		this.expiresInTime = expiresIn * 1000 + date.getTime() - 10000;
		this.expiresTime = date.getTime() + expiresIn * 1000 * 60 * 60 * 24 * 30 - 10000;
		this.refreshToken = refreshToken;
		this.openid = openid;
		this.scope = scope;
	}

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public long getExpiresIn() {
		return expiresIn;
	}

	public void setExpiresIn(long expiresIn) {
		this.expiresIn = expiresIn;
	}

	public long getExpiresInTime() {
		return expiresInTime;
	}

	public void setExpiresInTime(long expiresInTime) {
		this.expiresInTime = expiresInTime;
	}

	public long getExpiresTime() {
		return expiresTime;
	}

	public void setExpiresTime(long expiresTime) {
		this.expiresTime = expiresTime;
	}

	public String getRefreshToken() {
		return refreshToken;
	}

	public void setRefreshToken(String refreshToken) {
		this.refreshToken = refreshToken;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}


	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

	public String getErrmsg() {
		return errmsg;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}
}
